package com.xingkeduo.controller.api.activity;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xingkeduo.controller.base.InitController;
import com.xingkeduo.model.param.ActivityCombinationParam;
import com.xingkeduo.model.param.ActivityUseParam;
import com.xingkeduo.model.param.MarketingParam.MarketingTypeEnum;
import com.xingkeduo.service.api.activity.PreferentialActivityService;
import com.xingkeduo.service.api.activity.UserActivityService;
import com.xingkeduo.util.Constant;
import com.xingkeduo.util.StringUtils;
import com.xingkeduo.util.tool.ResponseMessage;

import ch.qos.logback.classic.Logger;

/**
 * 
* @ClassName: PreferentialPackageController
* @Description: 优惠套餐-c端接口
* @author lixin
* @date May 3, 2019 3:12:54 PM
*
 */
@RestController
@RequestMapping(Constant.API_URL_PREFIX + "/discount/package")
public class PreferentialPackageController extends InitController {
	Logger logger =(Logger) LoggerFactory.getLogger(PreferentialPackageController.class);

	@Autowired
	UserActivityService userActivityService;
	@Autowired
	PreferentialActivityService preferentialActivityService;
	/**
	 * 
	* @Title: getRecommendedPackage 
	* @Description: 获取推荐组合套餐
	* @param @param storeId
	* @param @return    设定文件 
	* @return ResponseMessage    返回类型 
	* @throws 
	* @author lixin
	* @date May 6, 2019 2:16:23 PM
	 */
	@PostMapping("/getRecommendedPackage")
	public ResponseMessage getRecommendedPackage(@RequestBody ActivityCombinationParam param) {
		if(StringUtils.isNumeric(param.getNewUserType()) && param.getUserType()==null) {
			param.setUserType(Integer.parseInt(param.getNewUserType()));
		}
		return preferentialActivityService.getRecommendedPackage(param);
	}
	/**
	 * 
	* @Title: checkUserHasMarketingAndActivty 
	* @Description: 判定用户是否有活动和卡券活动
	* @param @param param
	* @param @return    设定文件 
	* @return ResponseMessage    返回类型 
	* @throws 
	* @author lixin
	* @date Jun 21, 2019 9:29:31 PM
	 */
	@PostMapping("/checkUserHasMarketingAndActivty")
	public ResponseMessage checkUserHasMarketingAndActivty(@RequestBody ActivityCombinationParam param) {
		return preferentialActivityService.checkUserHasMarketingAndActivty(param);
	}
	@PostMapping("/getUserActivity")
	public ResponseMessage getUserActivity(@RequestBody ActivityCombinationParam param) {
		this.initUserInParams(param);
		return preferentialActivityService.getUserActivity(param);
	}
	@PostMapping("/getUserCoupon")
	public ResponseMessage getUserCoupon(@RequestBody ActivityCombinationParam param) {
		this.initUserInParams(param);
		return preferentialActivityService.getUserCoupon(param);
	}
	@PostMapping("/getUserCard")
	public ResponseMessage getUserCard(@RequestBody ActivityCombinationParam param) {
		this.initUserInParams(param);
		return preferentialActivityService.getUserCard(param);
	}
	@PostMapping("/checkUserActivity")
	public ResponseMessage checkUserActivity(@RequestBody ActivityUseParam param) {
		if(param.getPreferentialType() == null) {
			return ResponseMessage.error("缺少优惠类型参数",500);
		}
		if(param.getActivityId() == null && param.getMarketingReceiveHistoryId() == null) {
			return ResponseMessage.error("活动及权益ID均为空",500);
		}
		if(param.getMarketingReceiveHistoryId() != null) {
			if(param.getMarketingType()==null) {
				return ResponseMessage.error("券卡类型未知",500);
			}
			MarketingTypeEnum marketingTypeEnum = MarketingTypeEnum.parseOrderStatus(param.getMarketingType());
			if(marketingTypeEnum == MarketingTypeEnum.UNKNOWN) {
				return ResponseMessage.error("券卡类型未知",500);
			}
			param.setMarketingType(marketingTypeEnum.getCode());
		}
		return preferentialActivityService.checkUserActivity(param);
	}
	/**
	 * 
	* @Title: getStoreHelpPaymentActivityList 
	* @Description: 获取门店的分流活动 
	* @param @param storeId
	* @param @return    设定文件 
	* @return ResponseMessage    返回类型 
	* @throws 
	* @author lixin
	* @date May 17, 2019 10:02:41 AM
	 */
	@RequestMapping("/getStoreBypassFlowActivityDetail")
	public ResponseMessage getStoreBypassFlowActivityDetail(@RequestBody ActivityCombinationParam param) {
		if(param.getStoreId() == null ) {
			return ResponseMessage.error("缺少店铺id",500);
		}
		if(param.getAppointmentDate() == null ) {
			return ResponseMessage.error("缺少申请时间",500);
		}
		if(param.getHairServiceOriginPrice() == null ) {
			return ResponseMessage.error("缺少服务价格",500);
		}
		if(param.getUserId() == null ) {
			return ResponseMessage.error("缺少用户信息",500);
		}
		return preferentialActivityService.getStoreBypassFlowActivityList(param);
	}
	
	/**
	 * 
	* @Title: getStoreHelpPaymentActivityList 
	* @Description: 获取门店的分流活动 
	* @param @param storeId
	* @param @return    设定文件 
	* @return ResponseMessage    返回类型 
	* @throws 
	* @author lixin
	* @date May 17, 2019 10:02:41 AM
	 */
	@RequestMapping("/getBypassFlowActivityTime")
	public ResponseMessage getBypassFlowActivityTime(Long storeId,Long hairdresserId,Long hairServiceId, String startDate,String endDate) {
		if(storeId == null ) {
			return ResponseMessage.error("缺少店铺id",500);
		}
		if(hairdresserId == null ) {
			return ResponseMessage.error("缺少发型师ID",500);
		}
		if(hairServiceId == null ) {
			return ResponseMessage.error("缺少服务ID",500);
		}
		if(StringUtils.isBlank(startDate)) {
			return ResponseMessage.error("缺少预约开始时间",500);
		}
		if(StringUtils.isBlank(endDate)) {
			return ResponseMessage.error("缺少预约开始时间",500);
		}
		return preferentialActivityService.getStoreBypassFlowActivityTime(storeId,hairdresserId,hairServiceId, startDate,endDate);
	}
	
	@RequestMapping("/getUserCardAuthInfo")
	public ResponseMessage getUserCardAuthInfo(Long userId) {
		if(userId == null ) {
			return ResponseMessage.error("缺少用户id",500);
		}
		return preferentialActivityService.getUserCardAuthInfo(userId);
	}
}
